package com.edu.neusoft.widgetest112gxl;

import android.content.Intent;
import android.support.annotation.IdRes;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private EditText inputtext;
    private Button txtbutton,changebutton, sexbutton;
    private RadioButton radioButton,radioButton2;
    private ImageView imageView;
    private ImageButton imageButton;
    private RadioGroup radioGroup;
    private CheckBox cb_ba,cb_foot,cb_fea;
    private Button getbutton;
    private void init(){
        inputtext = (EditText)findViewById(R.id.inputtext);
        txtbutton = (Button)findViewById(R.id.txtbutton);
        changebutton = (Button)findViewById(R.id.changebutton);
        imageView = (ImageView)findViewById(R.id.imageView);
        imageButton = (ImageButton)findViewById(R.id.imageButton2);
        sexbutton = (Button)findViewById(R.id.sexbutton);
        radioButton = (RadioButton)findViewById(R.id.radioButton);
        radioButton2 = (RadioButton)findViewById(R.id.radioButton2);
        radioGroup = (RadioGroup)findViewById(R.id.radiogroup1);
        cb_ba = (CheckBox)findViewById(R.id.cb_ba);
        cb_foot = (CheckBox)findViewById(R.id.cb_foot);
        cb_fea = (CheckBox)findViewById(R.id.cb_fea);
        getbutton = (Button)findViewById(R.id.getbutton);

    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
        txtbutton.setOnClickListener(this);
        changebutton.setOnClickListener(this);
        imageButton.setOnClickListener(this);
        sexbutton.setOnClickListener(this);
        getbutton.setOnClickListener(this);
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, @IdRes int i) {
                switch (i) {
                    case R.id.radioButton2: inputtext.setText("男");break;
                    case R.id.radioButton: inputtext.setText("女");break;
                }
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.txtbutton:
                Toast.makeText(this, "内容是:"+inputtext.getText().toString(), Toast.LENGTH_SHORT).show();
                break;
            case R.id.changebutton:
                imageView.setImageResource(R.drawable.aaa);
                imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
                break;
            case R.id.imageButton2:
                Intent intent = new Intent(MainActivity.this,ButtonActivity.class);
                intent.putExtra("para1",inputtext.getText().toString());
                startActivity(intent);
                break;
            case R.id.sexbutton:
                if (radioButton2.isChecked()){
                    inputtext.setText("男");
                    break;
                }
                if (radioButton.isChecked()){
                    inputtext.setText("女");
                    break;
                }

            case R.id.getbutton:
                String str = "";
                if (cb_ba.isChecked()) str+="篮球 ";
                if (cb_fea.isChecked()) str+="羽毛球 ";
                if (cb_foot.isChecked()) str+="足球 ";
                inputtext.setText(str);
                break;
        }

    }
}